#ifndef PrimitivesI2CH
 #define PrimitivesI2CH

#define Dis     0
#define En      1


typedef enum
{
  NO_ERROR = 0,
  CRC_ERROR,
  ARB_LOST,
  NO_SLAVE,
  BUS_ERROR,
  TIME_OUT,
  BUF_OVERFLOW,
  I2C_BUSY,
  I2C_STRETCH
    
} STATUS_I2C;




  #define COMbit      0x02
  #define RDbit       0x01
  #define WRbit       0x00
  #define COMlen      5


/****************************************************************************************************/
/*                     I 2 C x C O N S E T   &   I 2 C x C O N C L R   B i t s                      */
/****************************************************************************************************/
  #define AAbit       ( 1 << 2 )   //
  #define SIbit       ( 1 << 3 )   //
  #define STObit      ( 1 << 4 )   //
  #define STAbit      ( 1 << 5 )   //
  #define I2ENbit     ( 1 << 6 )   //




/****************************************************************************************************/
/*                                      I 2 C 0   M A C R O S                                       */
/****************************************************************************************************/
  #define AA0on        I2C0CONSET = AAbit     //I2C0: AA flag set
  #define STO0on       I2C0CONSET = STObit    //I2C0: STOP flag set
  #define STA0on       I2C0CONSET = STAbit    //I2C0: START flag set
  #define I2C0en       I2C0CONSET = I2ENbit   //I2C1: interface enable
//
  #define AA0off       I2C0CONCLR = AAbit     //I2C0: AA flag reset
  #define SI0clr       I2C0CONCLR = SIbit     //I2C0: SI flag reset
  #define STA0off      I2C0CONCLR = STAbit    //I2C0: START flag reset
  #define I2C0dis      I2C0CONCLR = I2ENbit   //I2C0: interface disable
/****************************************************************************************************/


/****************************************************************************************************/
/*                                      I 2 C 1   M A C R O S                                       */
/****************************************************************************************************/
  #define AA1on        I2C1CONSET = AAbit     //I2C1: AA flag set
  #define STO1on       I2C1CONSET = STObit    //I2C1: STOP flag set
  #define STA1on       I2C1CONSET = STAbit    //I2C1: START flag set
  #define I2C1en       I2C1CONSET = I2ENbit   //I2C1: interface enable
//
  #define AA1off       I2C1CONCLR = AAbit     //I2C1: AA flag reset
  #define SI1clr       I2C1CONCLR = SIbit     //I2C1: SI flag reset
  #define STA1off      I2C1CONCLR = STAbit    //I2C1: START flag reset
  #define I2C1dis      I2C1CONCLR = I2ENbit   //I2C1: interface disable
/****************************************************************************************************/


/****************************************************************************************************/
/*                                      I 2 C 2   M A C R O S                                       */
/****************************************************************************************************/
  #define AA2on        I2C2CONSET = AAbit     //I2C2: AA flag set
  #define STO2on       I2C2CONSET = STObit    //I2C2: STOP flag set
  #define STA2on       I2C2CONSET = STAbit    //I2C2: START flag set
  #define I2C2en       I2C2CONSET = I2ENbit   //I2C1: interface enable
//
  #define AA2off       I2C2CONCLR = AAbit     //I2C2: AA flag reset
  #define SI2clr       I2C2CONCLR = SIbit     //I2C2: SI flag reset
  #define STA2off      I2C2CONCLR = STAbit    //I2C2: START flag reset
  #define I2C2dis      I2C2CONCLR = I2ENbit   //I2C2: interface disable
/****************************************************************************************************/











/****************************************************************************************************/
/*                         S T A T U S   C O D E   S T A T E S   D E F I N E                        */
/****************************************************************************************************/
  #define NoStat         0xF8    //No Relevant State information available, SI=0
  #define BusERR         0x00    //BUS ERROR during master or selected slave modes
//ARBITRATION LOST WHILE DEVICE WAS IN MASTER MODE:
  #define AlNoADR        0x38    //Arbitration lost, device enter non adressed slave block
  #define AlSLAwA        0x68    //Arbitration lost, SLA+W has been recieved, ACK has been return
  #define AlGENwA        0x78    //Arbitration lost, GEN call adr has been recieved, ACK has been return
  #define AlSLArA        0xB0    //Arbitration lost, SLA+R has been recieved, ACK has been return
//MASTER MODE:
  #define mSTART         0x08    //A START condition has been transmitted
  #define mReSTART       0x10    //A repeated START condition has been transmitted
  #define mSLAwA         0x18    //SLA+W has been transmitted, ACK has been recieved
  #define mSLAwNA        0x20    //SLA+W has been transmitted, NACK has been recieved
  #define mDATwA         0x28    //DATA byte has been transmitted, ACK has been recieved
  #define mDATwNA        0x30    //DATA byte has been transmitted, NACK has been recieved
//
  #define mSLArA         0x40    //SLA+R has been transmitted, ACK has been recieved
  #define mSLArNA        0x48    //SLA+R has been transmitted, NACK has been recieved
  #define mDATrA         0x50    //DATA byte has been received, ACK has been return
  #define mDATrNA        0x58    //DATA byte has been  received, NACK has been return
//SLAVE MODE:
  #define sSLAwA         0x60    //Own SLA+W has been recieved, ACK has been return
  #define sGENwA         0x70    //General Call address has been recieved, ACK has been return
  #define sDATwA         0x80    //after own SLA, DATA byte has been received, ACK has been return
  #define sDATwNA        0x88    //after own SLA, DATA byte has been received, NACK has been return
  #define sGDATwA        0x90    //after GEN adr, DATA byte has been received, ACK has been return
  #define sGDATwNA       0x98    //after GEN adr, DATA byte has been received, NACK has been return
  #define sSTPw          0xA0    //STOP 0r RESTART condition has been received
//
  #define sSLArA         0xA8    //Own SLA+R has been recieved, ACK has been return
  #define sDATrA         0xB8    //after own SLA, DATA byte has been transmitted, ACK has been received
  #define sDATrNA        0xC0    //after own SLA, DATA byte has been transmitted, NACK has been received
  #define sLDATrA        0xC8    //after own SLA, last DATA byte has been transmitted, ACK has been received
/****************************************************************************************************/
/****************************************************************************************************/





#endif